 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using CMN.Models;
using CMN.Models.Interfaces;
using CMN.Entity;
using CMN.Controllers;
using CMN.Controllers.Filters;
using CMN.Common;
using System.Text;
using CMN.UI;
using CMN.Framework;
using CMN.Config;
namespace CMN.Controllers
{
    
    [LoggerFilter()]
    [ExceptionFilter()]
    [ExecutionTimingAttribute()]
    public class DefaultController : Controller
    {
       [CompressFilter]
       [CacheFilterAttribute]
        public string Index(string type)
        {
            //System.Web.HttpBrowserCapabilitiesBase myBrowserCaps = this.HttpContext.Request.Browser;
            //int isMobile = myBrowserCaps.IsMobileDevice ? 1 : 0;
            //if (isMobile == 1)
            //{
            //    if (type != "wap")
            //    {
            //        type = "wap";
            //    }
            //}
            PageHelperEntity pageHelper = new PageHelperEntity();
            if (!string.IsNullOrEmpty(type))
            {
                if (type == "wap")
                    pageHelper.TType = TemplateType.Phone;
            }
            pageHelper.Url = "/";
            pageHelper.Type = PageType.IndexPage;
            SiteConfigInfo siteInfo = SiteConfigs.GetSiteConfig();
           
            pageHelper.Title = siteInfo.Title;
            pageHelper.Description = siteInfo.Description;
            pageHelper.Keywords = siteInfo.Keywords;
            if (siteInfo.IsHtml != 0)
            {
                if (!string.IsNullOrEmpty(type))
                {
                    type = string.Concat(type, "\\");
                }
               
              
                string path = string.Concat(Utils.GetServerPath(), "App_Data\\html\\",type,"default.htm");
                string content = string.Empty;
                if (Utils.FileIsOld(path, siteInfo.CacheSecond))
                {
                    content = Utils.GetFileContent(path, Encoding.GetEncoding("gb2312"));

                }
                else
                {
                    content = getIndex(pageHelper);
                    Utils.CreateFile(path, content, null);
                }

                return content;
            }
            else
                return getIndex(pageHelper);

        }
       private string getIndex(PageHelperEntity pageHelper)
       {
         
           BaseTemplateDisplay articleTemplate = new BaseTemplateDisplay(pageHelper);
           string strContent = string.Empty;
           strContent = articleTemplate.Display();
           articleTemplate.Dispose();

           pageHelper = null;
           return strContent;
       }
              
       


        
    }
}
